package com.ruoyi.report.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.report.domain.Bgbh;
import com.ruoyi.report.service.IBgbhService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 报告编号管理Controller
 * 
 * @author ruoyi
 * @date 2023-10-17
 */
@RestController
@RequestMapping("/report/bgbh")
@Api(value="报告编号管理",tags = "报告编号管理")
public class BgbhController extends BaseController
{
    @Autowired
    private IBgbhService bgbhService;

    /**
     * 查询报告编号管理列表
     */
    @PreAuthorize("@ss.hasPermi('report:bgbh:list')")
    @GetMapping("/list")
    @ApiOperation(value="查询报告编号管理列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "pageNum", value = "页数", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "pageSize", value = "每页记录数", required = true, dataType = "String"),
    })
    public TableDataInfo list(Bgbh bgbh)
    {
        startPage();
        List<Bgbh> list = bgbhService.selectBgbhList(bgbh);
        return getDataTable(list);
    }

    /**
     * 根据受检设备类型获取最大编号
     */
    @PreAuthorize("@ss.hasPermi('report:bgbh:query')")
    @GetMapping("/getMaxBgbh")
    @ApiOperation(value="根据受检设备类型获取最大编号")
    @ApiImplicitParam(paramType="query", name = "equType", value = "受检设备类型", required = true, dataType = "String")
    public AjaxResult getMaxBgbh(@RequestParam String equType)
    {
        return AjaxResult.success(bgbhService.selectBgbhMax(equType));
    }

    /**
     * 导出报告编号管理列表
     */
    @PreAuthorize("@ss.hasPermi('report:bgbh:export')")
    @Log(title = "报告编号管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Bgbh bgbh)
    {
        List<Bgbh> list = bgbhService.selectBgbhList(bgbh);
        ExcelUtil<Bgbh> util = new ExcelUtil<Bgbh>(Bgbh.class);
        util.exportExcel(response, list, "报告编号管理数据");
    }

    /**
     * 获取报告编号管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('report:bgbh:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value="获取报告编号管理详细信息")
    @ApiImplicitParam(paramType="query", name = "id", value = "主键", required = true, dataType = "String")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(bgbhService.selectBgbhById(id));
    }

    /**
     * 新增报告编号管理
     */
    @PreAuthorize("@ss.hasPermi('report:bgbh:add')")
    @Log(title = "报告编号管理", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value="新增报告编号管理")
    public AjaxResult add(@ApiParam(name="报告编号",value="传入json格式",required=true)@RequestBody Bgbh bgbh)
    {
        return toAjax(bgbhService.insertBgbh(bgbh));
    }

    /**
     * 修改报告编号管理
     */
    @PreAuthorize("@ss.hasPermi('report:bgbh:edit')")
    @Log(title = "报告编号管理", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value="修改报告编号管理")
    public AjaxResult edit(@ApiParam(name="报告编号",value="传入json格式",required=true)@RequestBody Bgbh bgbh)
    {
        return toAjax(bgbhService.updateBgbh(bgbh));
    }

    /**
     * 删除报告编号管理
     */
    @PreAuthorize("@ss.hasPermi('report:bgbh:remove')")
    @Log(title = "报告编号管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation(value="删除报告编号管理")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(bgbhService.deleteBgbhByIds(ids));
    }

    /**
     * 根据报告编号删除报告
     */
    @DeleteMapping("/deleteBh")
    public AjaxResult deleteBh(@RequestParam String bgbh){
        return toAjax(bgbhService.deleteBgbhBybh(bgbh));
    }
}
